﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using System.Windows;

namespace AssignmentsManage.Converters
{
    public class CourseCodeToCoursePropertyConverter : DependencyObject, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && Holder != null)
            {
                string code = value.ToString();
                string property = parameter.ToString();

                if (property == "IDColour")
                {
                    return Holder.getCourseByCode(code).IDColour;
                }
                else if (property == "Title")
                {
                    return Holder.getCourseByCode(code).Title;
                }
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException("MethodToValueConverter can only be used for one way conversion.");
        }

        // Dependency Property
        public static readonly DependencyProperty HolderProperty =
             DependencyProperty.Register("Holder", typeof(DataClasses.DataHolder),
             typeof(CourseCodeToCoursePropertyConverter), new FrameworkPropertyMetadata(null));

        // .NET Property wrapper
        public DataClasses.DataHolder Holder
        {
            get { return (DataClasses.DataHolder)GetValue(HolderProperty); }
            set { SetValue(HolderProperty, value); }
        }

    }
}
